<?php

class story extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('story_model');
        $this->load->helper('url');
        if (!isset($_SESSION['user'])) {
           // redirect(base_url());
        }
    }

    public function diagnostic($level = '') {
        if (empty($level)) {
            $data['story'] = $this->story_model->getDiagnosticStory();
            $_SESSION['story_id'] = $data['story']['story_id'];
            $_SESSION['book_number'] = $data['story']['book_number'];
            $data['title'] = 'Diagnostic Level 1';
            $data['color'] = $data['story']['colorhex'];
            $_SESSION['folder'] = 'diagnostic';
            $_SESSION['type'] = 'D';
            $this->load->view('templates/header', $data);
            $this->load->view('story', $data);
            $this->load->view('templates/footer');
        } else {
            $data['story'] = $this->story_model->getDiagnosticStory($level);
            $_SESSION['story_id'] = $data['story']['story_id'];
            $_SESSION['book_number'] = $data['story']['book_number'];
            $data['title'] = 'Diagnostic Level ' . $level;
            $data['color'] = $data['story']['colorhex'];
            $_SESSION['folder'] = 'diagnostic';
            $_SESSION['type'] = 'D';
            $this->load->view('templates/header', $data);
            $this->load->view('story', $data);
            $this->load->view('templates/footer');
        }
    }
    
    public function get($storyid){
        $data['story'] = $this->story_model->testing($storyid);
            $_SESSION['story_id'] = $data['story']['story_id'];
            $_SESSION['book_number'] = $data['story']['book_number'];
            $data['title'] = 'Book Number: ' . $_SESSION['book_number'];
            $data['color'] = $data['story']['colorhex'];
            $_SESSION['folder'] = $data['story']['level_name'];
            $this->load->view('templates/header', $data);
            $this->load->view('story', $data);
            $this->load->view('templates/footer');
    }

    public function display() {
        $criteria = $_SESSION['criteria']['id'];
        $level = $_SESSION['criteria']['level'];
        if(!isset($_SESSION['criteria'])){
            $location = base_url('student/readStory');
            redirect($location);
        }
        unset($_SESSION['criteria']);
        $data['story']=$this->story_model->getStory($criteria,$level);
        if(!empty($data['story'])){
        $_SESSION['story_id'] = $data['story']['story_id'];
            $_SESSION['book_number'] = $data['story']['book_number'];
            $data['title'] = 'Book Number: ' . $_SESSION['book_number'];
            $data['color'] = $data['story']['colorhex'];
            $_SESSION['folder'] = $data['story']['level_name'];
            $this->load->view('templates/header', $data);
            $this->load->view('story', $data);
            $this->load->view('templates/footer');
    }else {
        $location = base_url('student/readStory');
            redirect($location);
    }
    }

}

?>
